#ifndef FPRINTTHREAD_H
#define FPRINTTHREAD_H

#include <QThread>
#include <QDebug>
extern "C"
{
    #include <libfprint/fprint.h>
}

class EnrollProcess : public QThread
{
    Q_OBJECT

private:
    struct fp_dev *openedDevice;
    struct fp_print_data *data;
    struct fp_img *img;
    int fingerprint;
    int status;
    bool stopped;

public:
    EnrollProcess(fp_dev *device, int fingerprint)
    {
        this->openedDevice = device;
        this->fingerprint = fingerprint;
        this->status = -1;
        this->data = NULL;
        this->img = NULL;
    }

    void run()
    {
        qDebug() << "begin";
      status = fp_enroll_finger_img(openedDevice, &data, &img);
    qDebug() << "ended";
            while(status != FP_ENROLL_COMPLETE)
            {
                emit statusChanged(status);
                sleep(1);
                emit statusChanged(-1);
                status = fp_enroll_finger_img(openedDevice, &data, &img);
            }
            emit statusChanged(status);
            emit sendData(data);
         fp_img_standardize(img);


            // Make the fp_img free
            fp_img_free(img);
            img = NULL;

            // Make the fp_print_data free
            fp_print_data_free(data);
            data = NULL;
    }

signals:
    void statusChanged(int status);
    void sendData(fp_print_data *data);
   // void sendImage(fp_img *img);

public slots:

    void free()
    {
//        // Make the fp_img free
//        fp_img_free(img);
//        img = NULL;
//
//        // Make the fp_print_data free
//        fp_print_data_free(data);
//        data = NULL;
//
//        qDebug() << "free()";
    }

    void stop()
    {
//        setTerminationEnabled(true);
//        terminate();

        qDebug() << "stopped";
    }
};

#endif // FPRINTTHREAD_H
